package panel.status;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JLabel;
import javax.swing.JPanel;

import panel.canvas.CanvasObserver;
import panel.canvas.CanvasPanel;
import camera.Camera;
import window.Axis;

public class StatusPanel extends JPanel implements CanvasObserver {

	List<JLabel> _texts = new ArrayList<JLabel>();
	private JLabel mouseLabel;
	private JLabel cameraLabel;
	
	public StatusPanel() {
		
		setLayout(new FlowLayout(FlowLayout.LEFT));
		setBackground(Color.LIGHT_GRAY);
		
		// Create fields
		
		mouseLabel = new JLabel("Mouse: [ | ]");
		cameraLabel = new JLabel("Camera (eye): [ | | ]");
		
		add(mouseLabel);
		add(cameraLabel);
	}
	
	public void updateMousePosition( Point mouse ) {
		mouseLabel.setText("Mouse: [" + mouse.x + " | " + mouse.y + "]");
	}
	
	public void updateCameraPosition( Camera camera ) {
		cameraLabel.setText(String.format(
				"Camera (eye): [%1.1f | %1.1f | %1.1f] Camera (target): [%1.1f | %1.1f | %1.1f]",
				camera.getEyePosition(Axis.X), camera.getEyePosition(Axis.Y), camera.getEyePosition(Axis.Z),
				camera.getTargetPosition(Axis.X), camera.getTargetPosition(Axis.Y), camera.getTargetPosition(Axis.Z) ));
	}
	
	/* ----------------------------------------------------
	 * Canvas observer update function
	 */
	
	public void update(CanvasPanel canvas) {
		updateMousePosition(new Point(canvas.getMouseX(), canvas.getMouseY()));
		updateCameraPosition( canvas.getCamera() );
	}
}